<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>页面相关方法</title>
</head>
<body>
<input type="text">
<input type="button" value="按钮" onclick="f()">
<input type="button" value="平方" onclick="f1()">
<div>div</div>
<script>
  let i = document.querySelector("input");
  let d = document.querySelector("div");
  function f() {
    alert(i.value);
    d.innerText = i.value;
  }
  function f1() {
    if (isNaN(i.value)){
      d.innerText = "输入错误";
      return;
    }
    d.innerText = i.value*i.value;
  }
</script>
</body>
</html>